package leetcode.erfen;

public class Test5 {
    public static void main(String[] args) {
        int[] nums = {-2, -1, -1, 0, 0, 1, 2, 3};
        int maximumCount = maximumCount(nums);
        System.out.println(maximumCount);
    }

    public static int maximumCount(int[] nums) {
        int min = lowerBound(nums, 0);
        int max = nums.length - lowerBound(nums, 1);
        return Math.max(min, max);
    }

    private static int lowerBound(int[] nums, int target) {
        int left = 0, right = nums.length - 1;
        while (left <= right) {
            int mid = (left + right) / 2;
            if (nums[mid] >= target) {
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        return left;
    }
}
